require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'

def react_native_post_install(installer)
	installer.pods_project.targets.each do |target|
		target.build_configurations.each do |config|
		  # Set 9.0 as min version for all
		  if Gem::Version.new('9.0') > Gem::Version.new(config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'])
			config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
		  end
		end
	end

	projects = installer.aggregate_targets
	  .map{ |t| t.user_project }
	  .uniq{ |p| p.path }
	  .push(installer.pods_project)

	arm_value = `/usr/sbin/sysctl -n hw.optional.arm64 2>&1`.to_i

	projects.each do |project|
	  project.build_configurations.each do |config|
		if arm_value == 1 then
		  config.build_settings.delete("EXCLUDED_ARCHS[sdk=iphonesimulator*]")
		else
		  config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
		end
	  end

	  project.save()
	end
  end

target 'MetaMask' do
  config = use_native_modules!
  # Comment the next line if you don't want to use dynamic frameworks
  # use_frameworks!

  use_react_native!(:path => config["reactNativePath"])

  # Pods for MetaMask
  pod 'React-RCTPushNotification', :path => '../node_modules/react-native/Libraries/PushNotificationIOS'

  use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })
  post_install do |installer|
	react_native_post_install(installer)
	# Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable these next few lines.
    flipper_post_install(installer)
  end
end
